#include "kernel.h"

/*
 *
 * memcpy function
 *
 */
void memcpy(void *dest, const void *src, int count)
{
        const unsigned char *sp = (const unsigned char *) src;
        unsigned char *dp = (unsigned char *) dest;
	while(count != 0) {
		*dp++ = *sp++;
		count --;
	}
}


/*
 *
 * memset function
 *
 */
void memset(void *dest, char val, int count)
{
	unsigned char *dp = (unsigned char *)dest;
	while(count >= 0) {
		*dp = val;
		dp ++;
		count --;
	}
}

/*
 *
 * memset word function
 *
 */
void memsetw(unsigned short *dest, unsigned short val, int count)
{
	unsigned short *temp = (unsigned short *)dest;
	while(count != 0) {
 		*temp++ = val;
		count --;
	}
}

/*
 *
 * strlen function
 *
 */
int strlen(unsigned char *str)
{
	int retval = 0;
	while(*str != (unsigned char) '\0') {
		str++;
		retval++;
	}
	return retval;
}


/*
 *
 * strcmp function
 *
 */
int strcmp(unsigned char *text1, unsigned char *text2)
{
	int i = 0, rvalue = 0;
	while ( i < strlen(text1)) {
		if ( text2[i] != text1[i] )
			rvalue += 1;
		i ++;
	}
	return rvalue;
}

/*
 *
 * strcpy function
 *
 */

void strcpy(unsigned char *src, unsigned char *dest)
{
	while(*src != '\0') {
		*dest = *src;
		src ++;
		dest ++;
	}
	*dest = '\0';
}
